#include "Level.h"

Level::Level() {
	startGame = 2700;
}

Level::~Level() {

}

void Level::loadLevel(int level) {
    lvl_cmds = vector<Command*>();
    if(level == 1) {
    	for(int i=1; i<=1000; i++){
    	startGame += 100;
   		int pos =((int)(rand()*time(NULL))%601) + 40;

   		int speedX = 0;
   		if(pos<200){
   		 speedX=((int)(rand()*time(NULL))%7);
   		}
   		if(pos>400){
   			speedX = -1*((int)(rand()*time(NULL))%7);
   		}
        addEnemyToQueue(startGame, SR_ENEMY_1, pos, 0, 90, 1, 1, PLAYER_BEAM_NORMAL, FLIGHT_NORMAL, speedX, 8);
    	}
    }
}


void Level::addEnemyToQueue(int timer, int image, int posX, int posY, int shotDelay, int damage, int armor, int beam, int flightType, int speedX, int speedY) {
    Command* c = new Command();

    c->cmd = 'E';
    c->timer = timer;
    c->p1 = SR_ENEMY_1;
    c->p2 = posX;
    c->p3 = posY;
    c->p4 = shotDelay;
    c->p5 = damage;
    c->p6 = armor;
    c->p7 = beam;
    c->p8 = flightType;
    c->p9 = speedX;
    c->p10 = speedY;

    lvl_cmds.push_back(c);
}

bool Level::isNextEvent() {
    if(lvl_cmds.size() > 0) {
         // cout << "SDL_GETTICKS(): " << SDL_GetTicks() << " levelstarttime: " << levelStartTime << " event timer: " << lvl_cmds.at(0)->timer << " event cmd: " << lvl_cmds.at(0)->cmd << " event p1: " << lvl_cmds.at(0)->p1<< endl;
     //   vector<Command*>::iterator ii = lvl_cmds.begin();
        if(SDL_GetTicks() - levelStartTime >= lvl_cmds.at(0)->timer ) {
            return true;
        }
    }
    return false;
}

Command* Level::nextEvent() {
    vector<Command*>::iterator ii = lvl_cmds.begin();
    return (*ii);
}


